package com.cwnu.onlinemall.controller;

import com.cwnu.onlinemall.pojo.MallSign;
import com.cwnu.onlinemall.pojo.ServerResult;
import com.cwnu.onlinemall.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

@RestController
@CrossOrigin
public class SignController {
    @Autowired
    SignService signService;

    @RequestMapping("/mallSign/selectAll")
    public ServerResult selectAll(){
        List<MallSign> mallSignList = signService.selectAll();
        return new ServerResult(0,"查询成功",mallSignList);
    }

    @RequestMapping("/mallSign/selectById")
    public ServerResult selectById(Integer id){
        MallSign mallSign=signService.selectById(id);
        return new ServerResult(0,"查询成功",mallSign);
    }

    @RequestMapping("/mallSign/insert")
    public ServerResult insert(MallSign mallSign){
        Integer insertRow = signService.insert(mallSign);
        if(insertRow>=1){
            return new ServerResult(0,"添加成功",null);
        }else{
            return new ServerResult(1,"添加失败",null);
        }
    }

    //获取当前时间
    @RequestMapping("/mallSign/GetDateTime")
    public ServerResult GetDateTime() {
        Calendar calendar= Calendar.getInstance();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
        String date;
        date = dateFormat.format(calendar.getTime());
        return new ServerResult(0,"添加成功",date);
    }

}
